; (function () {
	new Vue({
		el: '#projectGl',
		data: {
			isExtenseFlag: false,
			keyWord: '',
			pageNums: [{name: '10', code: '10'}, {name: '15', code: '15'}, {name: '20', code: '20'}],
			limit: ['10'],
			page: 1,
			tbTitleWidth: {},
			listMenu: [
				{name: '意向', num: '0', code: 'YX'},
				{name: '已关闭', num: '0', code: 'GB'},
				{name: '转运营', num: '0', code: 'YY'},
			],
			listMenuArrActive: [],
			listObj: {},
			rperson: { ids: [], name: null, list: []},
			provinceId: [],
			cityId: [],
			areaId: [],
			channelCategoryCode: [],
			channelNameCode: [],
			columns: '#',
			orders: '#',
			provinceList: [],
			cityList: [],
			areaList: [],
			keyword: '',
			channelCateArr: [],
			channelNameArr: [],
			power: JSON.parse(localStorage.getItem('permissions')),

			//自定义开始
			configType: 'WZ', //默认完整WZ     JD简单，WZ完整，自定义配置PZ
			module: '#',
			headArr: [],
			sortTableTitle: [],
			isScroll: false,
			isShowTableLayer: false,
			dateTimeUpdate: [],
			isActiveCode: '#',
			tbTitleWidth:{},
			listObj:{},
		},
		filters: {
			date (time) {
				if (!time) return '--'
				return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd HH:mm')
			},
			formatUndefined: function(item) {
			  if (!item) return '--'
			  if (typeof item == 'number') {
			  	if (!isNaN(item) && item.toString().length == 13) {
			  		return hlDateUtil.formatUTCDate(item, 'yyyy-MM-dd HH:mm')
			  	};
			  }
			  return item
			},
			formatNum: function(item) {
			  if (item === undefined) return '--'
			  return hlNumberUtil.formatNum(item)
			}
		},
		methods: {
			//项目管理tab
			resetTab () {
				this.page = 1;
				this.listMenuArrActive = [];
				this.listDt()
			},
			//去详情
			goTodetail(id){
				hlUrlUtil.goTo('projectDetail',{'id': id, 'ddtab':true,'from':'manage'},true)
			},
			selectStatus (item) {
				this.page = 1;
				setTimeout(() => {
					this.listDt()
				}, 300)
				if (this.listMenuArrActive.indexOf(item.code) == -1) {
					this.listMenuArrActive.push(item.code)
					return
				}
				this.listMenuArrActive.splice(this.listMenuArrActive.indexOf(item.code), 1)
			},
			//获取渠道分类
			channelCateDt () {
				hlhttp.get({
					url: 'configure/dict',
					data: {module_code: 'SCTZ', config_name: 'SCTZ_CHANNEL_CATE', parent_dict_code: '#'},
					success: (data) => {
						this.channelCateArr = hlArrayUtil.replaceData(data, [{key: 'dictName', rKey: 'name'}, {key: 'dictCode', rKey: 'code'}]);
					}
				})
			},
			//获取渠道名称
			channelNameDt () {
				hlhttp.get({
					url: 'configure/dict',
					data: {module_code: 'SCTZ', config_name: 'SCTZ_CHANNEL_NAME', parent_dict_code: this.channelCategoryCode[0]},
					success: (data) => {
						this.channelNameArr = hlArrayUtil.replaceData(data, [{key: 'dictName', rKey: 'name'}, {key: 'dictCode', rKey: 'code'}]);
					}
				})
			},
			//选择渠道分类
			selectedCC (item) {
				this.channelCategoryCode = [item[0].dictCode];
				this.channelNameArr = [];
				this.channelNameDt()
			},
			//选择渠道名称
			selectedCN (item) {
				this.channelNameCode = [item[0].dictCode];
			},
			//输入对接人进行搜索
			onInputDJR: function (e) {
			  if (!this.rperson.name) {
			    if (!e.data) {
			      this.rperson.name = '';
			      this.getDataGroup()
			      return
			    };
			    this.rperson.name = e.data;
			  }
			  this.getDataGroup()
			},
			//判断有没有ids
			ifrpersonIds: function () {
			  if (!this.rperson.ids.length) {
			    this.rperson.name = null
			  }
			},
			//设置对接人name，获取id
			setRperson: function (name, id) {
			  this.rperson.ids = [];
			  this.rperson.name = name;
			  this.rperson.ids.push(id)
			  this.rperson.list = [];
			},
			//搜索负责人工作组组员列表
			getDataGroup: function () {
			  this.rperson.ids = [];
			  hlhttp.get({
			    url: 'tenants/users/_search',
			    data: {
			      keyword: this.rperson.name || '#',
			      first_order:'Y'
			    },
			    success: (res) => {
			      this.rperson.list = res;
			      for (var i = 0; i < this.rperson.list.length; i++) {
			        if (this.rperson.name.match(res[i])) {
			          this.rperson.ids.push(res[i].id)
			        }
			      }
			    }
			  })
			},
			//展开收起
			openOffOn () {
				this.isExtenseFlag = !this.isExtenseFlag
			},
			//省
			provinceData () {
				hlhttp.get({
					url: 'sub_regions',
					data: {region_id: '1'},
					success: (data) => {
						this.provinceList = hlArrayUtil.replaceData(data, [{key: 'regionId', rKey: 'code'}]);
					}
				})
			},
			//设置省
			setProvince (data) {
				this.provinceId = [data[0].regionId];
				this.cityData()
				this.areaList = [];
			},
			//市
			cityData () {
				hlhttp.get({
					url: 'sub_regions',
					data: {region_id: this.provinceId[0]},
					success: (data) => {
						this.cityList = hlArrayUtil.replaceData(data, [{key: 'regionId', rKey: 'code'}]);
					}
				})
			},
			setCity (data) {
				this.cityId = [data[0].regionId];
				this.areaData()
			},
			//区
			areaData () {
				hlhttp.get({
					url: 'sub_regions',
					data: {region_id: this.cityId[0]},
					success: (data) => {
						this.areaList = hlArrayUtil.replaceData(data, [{key: 'regionId', rKey: 'code'}]);
					}
				})
			},
			setArea (data) {
				this.areaId = [data[0].regionId];
			},
			//新增
			add () {
				hlUrlUtil.goTo('marketAdd', {ddtab: true,'from':'manage'}, true)
			},
			//重置
			reset () {
				this.keyword = ''
				this.rperson.ids = [];
				this.rperson.name = [];
				this.channelNameArr = []
				this.provinceId = []
				this.cityId  = []
				this.areaId  = []
				this.channelCategoryCode = []
				this.channelNameCode = [];
				this.listMenuArrActive = []
				this.columns = '#'
				this.orders = '#'
				this.isActiveCode = '',
				this.limit = ['10'];
				this.page = 1;
				this.listDt()
			},
			//翻页数量
			turnPage (item) {
				this.page = 1;
				this.limit = [item[0].code];
				this.listDt()
			},
			//项目数量
			listNumberDt () {
				hlhttp.get({
					url: 'market/expansion_proj_info/status_count',
					data: {
						"str": this.keyword || '#',// 信息搜索(项目名称proj_name、联系人contact_name、联系人电话contact_phone_num、创建人creator_name)
						"assignee_id": this.rperson.ids.length ? this.rperson.ids.toString() : '#',// 对接人
						"province_id": this.provinceId.length ? this.provinceId[0] : '#',// 项目所在地：省份
						"city_id": this.cityId.length ? this.cityId[0] : '#',// 项目所在地：城市
						"district_id": this.areaId.length ? this.areaId[0] : '#',// 项目所在地：区县

						"channel_category_code": this.channelCategoryCode.length ? this.channelCategoryCode[0] : '#',// 渠道分类
						"channel_name_code": this.channelNameCode.length ? this.channelNameCode[0] : '#',// 渠道名称
					},
					success: (data) => {
						this.listMenu.map(item => {
							switch (item.code){
								case 'YX':
								item.num = data.yXCount
									break;
								case 'GB':
								item.num = data.gBCount
									break;
								case 'YY':
								item.num = data.yYCount
									break;
								default:
								item.num = 0
									break;
							}
						})
					}
				})
			},


			//市场拓展项目管理列表
			listDt () {
				hlhttp.get({
					url: 'market/expansion_proj_info/_search',
					data: {
						"str": this.keyword || '#',// 信息搜索(项目名称proj_name、联系人contact_name、联系人电话contact_phone_num、创建人creator_name)
						"assignee_id": this.rperson.ids.length ? this.rperson.ids.toString() : '#',// 对接人
						"province_id": this.provinceId.length ? this.provinceId[0] : '#',// 项目所在地：省份
						"city_id": this.cityId.length ? this.cityId[0] : '#',// 项目所在地：城市
						"district_id": this.areaId.length ? this.areaId[0] : '#',// 项目所在地：区县

						"channel_category_code": this.channelCategoryCode.length ? this.channelCategoryCode[0] : '#',// 渠道分类
						"channel_name_code": this.channelNameCode.length ? this.channelNameCode[0] : '#',// 渠道名称
						"status": this.listMenuArrActive.length ? this.listMenuArrActive.toString() : '#',// 状态：意向,已关闭,转运营   逗号,连接
						"columns": this.columns,
						"orders": this.orders,

						"limit": this.limit[0],// 分页参数，一页显示数量
						"page": this.page + ''// 分页参数，页码
					},
					success: (data) => {
						this.listObj = data;
						$("#page").initPage(data.totalPage, this.page, (n) => {
						  if (this.page == n) {
						    return
						  }
							this.page = n;
						  this.listDt();
						});
						this.listNumberDt()
					}
				})
			},



      //更新时间
      sortBySTTime (item) {
				this.isActiveCode = item.value;
        this.orders = item.orders
				this.columns = item.columns
        this.listDt()
      },
      //获取自定义表头配置状态
			configTypeDt () {
				hlhttp.get({
					url: 'configure/customize_column_header/type',
					data: {module: 'SCTZ_XMGL'},
					success: (data) => {
						this.configType = data.configType;
						this.customizeHeaderDt()
					}
				})
			},
			//获取自定义表头配置信息
			customizeHeaderDt () {
				hlhttp.get({
					url: 'configure/customize_column_header',
					data: {module: 'SCTZ_XMGL'},
					success: (data) => {
            this.headArr = data.customConfigList;
					}
				})
			},
			//简单完整配置切换
			selectTableType(obj) {
        this.configType = obj.code;
				this.updateConfigType()
      },
			//更新自定义表头配置状态
			updateConfigType () {
				hlhttp.put({
					url: 'configure/customize_column_header/type',
					data: {module: 'SCTZ_XMGL', config_type: this.configType},
					success: () => {}
				})
			},
			// 确定提交自定义表格
      confirmSubmitTable(data) {
				let dataArr = [];
				data.map((item, index) => {
					dataArr.push({
						"base_flag": item.baseFlag,
            "seq": item.seq,
            "custom_show_flag": item.customShowFlag,
            "custom_seq": item.newIndex,
            "custom_display_name": item.customDisplayName,
            "union_table_part": item.unionTablePart,
            "dict_code": item.dictCode,
            "config_type": item.configType,
            "name": item.name,
            "value": item.value,
            "style_width": item.styleWidth,
            "flex": item.flex,
            "order_flag": item.orderFlag,
            "order_name": item.orderName
					})
				})
				hlhttp.put({
					url: 'configure/customize_column_header',
					data: {
						module: 'SCTZ_XMGL',
						custom_config: JSON.stringify(dataArr)
					},
					success: (data) => {
						hl.toast('操作成功')
						this.updateConfigType()
					}
				})
      },

		},
		mounted () {
			hlSelectUi()
			this.provinceData()
			this.listDt()
			this.channelCateDt()
			//自定义
			this.listNumberDt()
			this.configTypeDt()
			var _this = this;
			document.body.onclick = function () {
        _this.rperson.list = [];
      }
		}
	})
} ())
